package com.vtc.session12;

import com.vtc.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class StudentAddActivity extends Activity implements OnClickListener{

	private TextView txtName;
	private TextView txtAddr;
	private TextView txtAge;
	private Button btnSave;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.studentadd_activity);
		
		txtName = (TextView) findViewById(R.id.studentadd_txtName);
		txtAddr = (TextView) findViewById(R.id.studentadd_txtAddr);
		txtAge  = (TextView) findViewById(R.id.studentadd_txtAge);
		btnSave = (Button) findViewById(R.id.studentadd_btnSave);
		
		btnSave.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
         if(v==btnSave){
        	 String name= txtName.getText().toString();
        	 String addr= txtAddr.getText().toString();
        	 int age =Integer.parseInt(txtAge.getText().toString());
        	 
        	 Student st = new Student(name, addr, age);
        	 
        	 StudentAdapter adapter = new StudentAdapter(this);
        	 adapter.add(st);
        	 // quay lia trang list
        	 Intent i = new Intent(this,StudentListActivity.class);
        	 startActivity(i);
         }
	}
}
